package Controller;

import java.io.IOException;
import java.sql.Connection;

import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


import DAO.JNDI_DAO;

/**
 * Servlet implementation class BindServlet
 */
@WebServlet("/BindServlet")
public class BindServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
	Context ctx;
    public BindServlet() {
        super();
		ctx=DAO.JNDI_DAO.getContext();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		if(request.getParameter("bindName")!=null&&request.getParameter("bindValue")!=null)
		{
			try {
				ctx.bind((String)request.getParameter("bindName"), request.getParameter("bindValue"));
				response.getOutputStream().print("successful");
			} catch (NamingException e) {
				// TODO Auto-generated catch block
				response.getOutputStream().print("failed");
				e.printStackTrace();
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			// TODO Auto-generated method stub
		doGet(request,response);
	}

}
